
import 'dart:async';

import 'package:flutter/services.dart';

const MethodChannel _kChannel = MethodChannel('com.ahj/aliPayPlugin');
typedef Future<dynamic> EventHandler(Map<String, dynamic> event);
class AliPayUtils {

  void addEventHandler({
      EventHandler onReceiveNotification,
      EventHandler onOpenNotification,
      EventHandler onReceiveMessage,
      EventHandler onflushData,
    }) {
      _kChannel.setMethodCallHandler(_handleMethod);
    }
  /**
   * sign 签名
   */
  static Future<String> aliPay(String sign) async {
    Map<String, dynamic> map = Map();
    map["sign"] = sign;
   return await _kChannel.invokeMethod('aliPay', map);
  }

  /**
   * sign 签名
   */
  static Future<String> aliPayResult() async {
    await _kChannel.invokeMethod('aliPayResult', null);
  }

  Future<Null> _handleMethod(MethodCall call) async {
      switch (call.method) {
        case "aliPayResult":
          return Future.value(call.arguments);
       /* case "flushData":
          return _flushData("121r4");*/
        default:
          throw new UnsupportedError("Unrecognized Event");
      }
    }
}